#pragma once

#include <render/Utils/MathUtils.h>
#include <render/Others/PerseusLibDefines.h>
#include <render/Primitives/Camera3D.h>
#include <cmath>
#include <string.h>
#include <memory>

namespace pwp {

class CameraCoordinateTransform
{
private:
  void decompKMatrix(VFLOAT source[3][4], VFLOAT cpara[3][4], VFLOAT trans[3][4]);

  VFLOAT norm(VFLOAT a, VFLOAT b, VFLOAT c) {
    return ((VFLOAT)sqrtf(a * a + b * b + c * c));
  }
  VFLOAT dot(VFLOAT a1, VFLOAT a2, VFLOAT a3, VFLOAT b1, VFLOAT b2, VFLOAT b3) {
    return (a1 * b1 + a2 * b2 + a3 * b3);
  }

public:
  VFLOAT* projectionMatrix;
  VFLOAT zFar, zNear, fovy;

  void SetProjectionMatrix(VFLOAT fovy, VFLOAT aspect, VFLOAT zNear, VFLOAT zFar);
  void SetProjectionMatrix(Camera3D* camera, VFLOAT zNear, VFLOAT zFar);
  void GetProjectionMatrix(VFLOAT *pmatrix) { for (int i=0; i< 16; i++) pmatrix[i] = projectionMatrix[i]; }
  void GetInvPMatrix(VFLOAT* prod);

  CameraCoordinateTransform(void);
  ~CameraCoordinateTransform(void);
};

}
